/**
 * Copyright 2009 University of Washington This code is released under the GPL version 3 - with a copy of the license
 * included
 * 
 * @author Maya Hao Li
 */
package seedpod.webapp.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import seedpod.kb2db.ClsMap;
import seedpod.kb2db.ModelMap;
import seedpod.kb2db.SlotMap;
import seedpod.model.rdb.MetaRdbCls;
import seedpod.webapp.Seedpod;

public class ActionConfigMetadata extends HttpServlet {

	private static final long	serialVersionUID	= 1L;

	@Override
	protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
	// do nothing
	}

	@Override
	protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
		String clsName = request.getParameter( "clsName" );
		PrintWriter out = response.getWriter();

		// make sure that clsName is defined. go to customize.jsp otherwise
		if ( clsName == null || clsName.trim().length() == 0 ) {
			out.println( "Please select a class from the <a href=\"../lims/customize.jsp\" customization page</a>. " );
			return;
		}

		ModelMap modelMap = Seedpod.getModelMap();
		ClsMap cls = modelMap.getClsMap( clsName );
		ArrayList<SlotMap> slots = cls.getSortedSlotMaps();

		// cls info
		cls.setUserDefinedName( request.getParameter( MetaRdbCls.USER_DEFINED_NAME ) );
		cls.setBrowserPattern( request.getParameter( MetaRdbCls.BROWSER_PATTERN ) );
		cls.setDocumentation( request.getParameter( MetaRdbCls.DOCUMENTATION ) );

		modelMap.updateClsMap( cls );

		// slot info update

	}

}
